#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<errno.h>
#include<netinet/in.h>
#include<arpa/inet.h>

#define My_PORT 8877;

int main()
{
	int socket_fd;
	struct sockaddr_in my_addr;	
	
	socket_fd = socket(AF_INET , SOCK_STREAM, 0);
	if(socket_fd == -1){
		printf(" create socket failed \n ");
		exit(1);
	}else{
		printf("socket_fd : %d\n",socket_fd);
	}

	bzero(&my_addr , sizeof(my_addr));
	my_addr.sin_family = AF_INET;
	my_addr.sin_port = My_PORT;
	my_addr.sin_addr.s_addr = htonl(INADDR_ANY);

	if(bind( socket_fd , (struct sockaddr *)&my_addr , sizeof(struct sockaddr)) == -1){
		printf("bind error \n");
		exit(1);
	}else{
		if(listen(socket_fd , 3) == -1){
			printf("listen failed \n");
			exit(1);
		}else{
			printf("listen success \n");
			if(accept(socket_fd,NULL,NULL) == -1 ){
				printf(" accept failed \n");
				exit(1);
			}else{
				printf("accept success \n");
				exit(1);
			}
		
		}
	}
}
